<?php
/**
 * Created by PhpStorm.
 * User: BlueIdeaLirui
 * Date: 2019/09/04
 * Time: 14:58
 */

namespace business\elasticsearch\repositories;

use business\elasticsearch\models\MaterialBasicModel;
use yii\elasticsearch\Query;

class MaterialBasicRepository
{
    /**
     * 查询材料列表
     * @param array $condition
     * @param array $include
     * @param int $from
     * @param int $size
     * @param array $highlight
     * @param array $orderBy
     * @return array
     */
    public function queryList(
        $condition = [],
        $include = [],
        $from = 0,
        $size = 0,
        $highlight = [],
        $orderBy = []
    ) {
        $query = (new Query())
            ->source($include)
            ->from(MaterialBasicModel::index(), MaterialBasicModel::type())
            ->query($condition);

        !empty($highlight) && $query->highlight($highlight);

        $query->offset($from)->limit($size);

        return [
            $query->count(),
            $query->all()
        ];
    }
}
